<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>

<h3>readFile.jsp</h3>

<h1>选择文件拷贝</h1>
	<form method="post" action="copyServlet.do">
		<%
		String rootStr = "";
		File[] roots = (File[])request.getAttribute("roots");
		
		if(roots != null){
			for(int i = 0; i < roots.length; i ++){
				File root = roots[i];
				rootStr = root.getPath();
				
				out.println(request.getAttribute("root"+rootStr)+"<br>");
				
				List<String> allFileList = (List<String>)request.getAttribute("allFileList"+rootStr);
				List<String> allDirList = (List<String>)request.getAttribute("allDirList"+rootStr);
				
				for(int j = 0 ; j < allFileList.size(); j ++){
					%>
					<input type="radio" name="file" value="<%=rootStr + allFileList.get(j) %>" />
					<a href="document\<%= allFileList.get(j) %>"><%=rootStr + allFileList.get(j) %></a><br> 
					<%
				}
				for(int j = 0 ; j < allDirList.size(); j ++){
					%>
					<%-- <a href="document\" <%=allDirList.get(j) %> "><%=rootStr + allDirList.get(j) %></a><br> --%>
					<input type="radio" name="file" value="<%=rootStr + allDirList.get(j) %>" />
					<a href="document\<%= allDirList.get(j) %>"><%=rootStr + allDirList.get(j) %></a><br> 
					<%
				}
				out.println("<br>");
			}
		} else {
			File root = (File)request.getAttribute("root");
			rootStr = root.getPath();
			out.println(root+"<br>");
		
			List<String> allFileList = (List<String>)request.getAttribute("allFileList"+rootStr);
			List<String> allDirList = (List<String>)request.getAttribute("allDirList"+rootStr);
			
			for(int j = 0 ; j < allFileList.size(); j ++){
				%>
				<input type="radio" name="file" value="<%=rootStr + "\\"+ allFileList.get(j) %>" />
				<%-- <a href="document\<%= allFileList.get(j) %>"><%=rootStr + "\\"+ allFileList.get(j) %></a><br> --%> 
				<%=rootStr + "\\"+ allFileList.get(j) %><br>
				<%
			}
			for(int j = 0 ; j < allDirList.size(); j ++){
				%>
				<%-- <a href="document\" <%=allDirList.get(j) %> "><%=rootStr + allDirList.get(j) %></a><br> --%>
				<input type="radio" name="file" value="<%=rootStr + "\\"+ allDirList.get(j) %>" />
				<%-- <a href="document\<%= allDirList.get(j) %>"><%=rootStr + "\\"+ allDirList.get(j) %></a><br> --%> 
				<%=rootStr + "\\"+ allDirList.get(j) %><br>
				<%
			}
			out.println("<br>");
		}
		%>
		<input type="submit" value="确定" /><br>
		<%
			//RequestDispatcher rd = application.getRequestDispatcher("/upload.jsp"); //定义请求地址
			//request.setAttribute("path", o)
			//rd.forward(request, response); //请求转发
		%>
		
		<h2><%=rootStr %></h2>
		<h2><%=java.net.URLEncoder.encode(rootStr,"UTF-8")%></h2>
		 
		<a href="upload.jsp?path=<%=java.net.URLEncoder.encode(rootStr,"UTF-8")%>">上传文件</a>
		
	</form>
	
</body>
</html>